<template>
	<view class="">
		<view class="search-box pt-0 pb-0">
			<u-search placeholder="搜索" shape="square" v-model="searchData.storeName" @search="onSearch" :showAction="false"/>
			<view class="custom-btn" @click.stop="$u.route('/pages/manageStores/edit')">申请新店</view>
		</view>
		<view class="my-list padding-0">
			<u-list v-if="dataList.length > 0" @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in dataList" :key="item.id">
					<view class="bg-white padding-20 border-b" @click="$u.route('/pages/manageStores/edit', {id: item.id})">
						<view>
							<text>{{item.storeName}}</text>
							<text class="fsize-28 ml-10">{{item.storeNumber}}</text>
						</view>
						<view class="">
							<view class="">
								<view class="">
									<text class="line-gray fsize-28">启动资金: {{item.investAmount}}</text>
									<text class="line-gray fsize-28 ml-10">已投资: {{item.investTotal}}</text>
								</view>
								<view class="">
									<text class="line-gray fsize-28">联系人: {{item.linkMan}}</text>
									<text class="line-gray fsize-28 ml-10">电话: {{item.mobile}}</text>
								</view>
							</view>
						</view>
						<view>
							<text class="line-gray fsize-28">地址: {{item.areaText}}{{item.address}}</text>
						</view>
						<view class="flex justify-end mt-20" @click.stop>
							<view>
								<u-button text="详情" color="#f29100" @click="$u.route('/pages/manageStores/details', {...item})"></u-button>
							</view>
							<view class="ml-10">
								<u-button text="删除" color="#e54d42" @click="onDel(index)"></u-button>
							</view>
							<view class="ml-10">
								<u-button text="分享" color="#19be6b" @click="onShare(item.id)"></u-button>
							</view>
						</view>
					</view>
				</u-list-item>
			</u-list>
			<u-empty v-else text="点击申请门店" marginTop="100"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				searchData:{
					storeName:'',
					status: 0,
					page: 1, 
					limit: 20,
				},
				dataList: []
			}
		},
		onLoad() {
			this.getPageList()
			uni.$on('upStoreApplyData', ()=>{
				this.onSearch()
			})
		},
		onUnload() {
			uni.$off('upStoreApplyData')
		},
		methods: {
			onDel(ix){
				const that = this
				uni.showModal({
					title: '提示',
					content: `是否删除${that.dataList[ix].storeName}?`,
					success: function (res) {
						if (res.confirm) {
							that.$reqJsonPost('StoreApplyDoDelete',{id: that.dataList[ix].id}).then(res=>{
								that.dataList.splice(ix , 1)
							})
						}
					}
				});
			},
			onShare(id){
				this.$reqJsonPost('StoreApplyGetApplyQrCode', {id: id}).then(res=>{
					uni.previewImage({
						urls: [res.data.data]
					})
				})
			},
			onSearch(){
				this.dataList = []
				this.searchData.page = 1
				this.getPageList()
			},
			getPageList(){
				this.$reqPost('StoreApplyGetPageList', this.searchData).then(res=>{
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.searchData.page++
						this.loadMore = true
					}else {
						this.loadMore = false
					}
				})
			},
			scrolltolower(){
				if(this.loadMore){
					this.getPageList()
				}
			}
		}
	}
</script>

<style>
</style>